Ext.define('vacake.controller.Home', {
    extend: 'Ext.app.Controller',

    config: {
        refs: {
            mainView: 'mainView',
            homeView: 'homeView',
            usersView: 'usersView',
            homeCarousel: 'homeView #homeCarousel',
            productList: 'homeView #productList',
            selectAreaButton: 'homeView #select_area',
            loginButton: 'homeView #loginButton',
            logoutButton: 'homeView #logoutButton'
        },
        control: {
            selectAreaButton: {
                tap: 'selectAreaButton_onTap'
            },
            loginButton: {
                tap: 'loginButton_onTap'
            },
            logoutButton: {
                tap: 'logoutButton_onTap'
            },
            productList: {
                itemtap: 'productShowView'
            },
            homeCarousel: {
                onTap: 'adProductShowView'
            }
        }
},
    selectAreaButton_onTap: function () {
        Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
        Ext.Viewport.animateActiveItem('areaSelectView', {type: 'slide', direction: 'left'});
    },
    loginButton_onTap: function () {
        Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
        Ext.Viewport.animateActiveItem('loginForm', {type: 'slide', direction: 'left'});
    },
    logoutButton_onTap: function () {
        Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
        var main =this.getMainView();
        var users=this.getUsersView();
        main.setActiveItem(users);
    },
    productShowView: function (list, index, element, record) {
        Ext.Viewport.mask({
            xtype: 'loadmask',
            message: '加载数据中...'
        });
        this.redirectTo('loadProduct/' + record.get('cpid'));
    },
    adProductShowView: function (cdaid, id) {
        if (id != "") {
            Ext.Viewport.mask({
                xtype: 'loadmask',
                message: '加载数据中...'
            });
            if(id.indexOf('about')!=-1){
                window.localStorage.setItem('more_caid', '29');
                Ext.Viewport.animateActiveItem('moreInfo', {type: 'slide', direction: 'left'});
                return false;
            }else{
                this.redirectTo('loadProduct/' + id );
                return false;
            }
        }
        return false;
    }


})
;